<!DOCTYPE html>
<html lang="en">
<head>
  <title>浩然金融中心管理平台</title>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"
        name="viewport">
  <#include "/common/csslib.html">
  <script type="text/javascript">
      var systemTableInfoTable;
      var selectType = "multiple";
  </script>
</head>
<body>
<div class="main-wrapper">
  <!-- start: MAIN CONTAINER -->
  <div class="main-container inner">
    <!-- start: PAGE -->
    <div class="main-content">
      <div class="container">
        <!-- 当前位置 begin -->
        <div class="row h-home-path">
          <div class="col-md-12 col-sm-12 col-lg-12">
            <ol class="breadcrumb">
              <li><i class="fa fa-home"></i>&nbsp;&nbsp;所在位置</li>
              <li>首页</li>
              <li class="active">表模型信息</li>
            </ol>
          </div>
        </div>
        <!-- 当前位置 end -->

        <!-- 查询筛选内容 bagin -->
        <div class="row h-main-search">
          <form action="javascript:;" method="post">
            <div class="col-md-1 col-sm-1 col-xs-1 text-right">
              <label class="control-labe h-form-label" for="tableCode">表编码：</label>
            </div>
            <div class="col-md-2 col-sm-2 col-xs-2">
              <input class="form-control" id="tableCode" name="tableCode" type="text" value=""/>
            </div>
            <div class="col-md-1 col-sm-1 col-xs-1 text-right">
              <label class="control-labe h-form-label" for="tableName">表名称：</label>
            </div>
            <div class="col-md-2 col-sm-2 col-xs-2">
              <input class="form-control" id="tableName" name="tableName" type="text" value=""/>
            </div>
            <div class="pull-right h-btn-group">
              <button class="btn btn-info" onclick="SystemTableInfoManager.search()" type="button"><i
                      class="fa fa-search">&nbsp;&nbsp;</i>查询
              </button>
              <@permission btnType="add" btnId="addBtn" btnValue="新增" op="sys:tableinfo:add"
              btnMethod="SystemTableInfoManager.addSystemTableInfo()"/>
              <button class="btn btn-default" type="reset"><i class="fa fa-mail-reply">&nbsp;&nbsp;</i>重置</button>
            </div>
          </form>
        </div>

        <!-- 表格 begin -->
        <div class="panel panel-white h-panel">
          <div class="pull-left h-btn-group">
            <@permission btnValue="同步数据库表信息" btnClass="btn btn-default" iconClass="fa fa-gear" btnId="syncBtn"
            op="sys:sync:table" btnMethod="SystemTableInfoManager.syncDatabaseInfo()"/>
            <@permission btnValue="清空模块数据库信息" btnClass="btn btn-default" iconClass="fa fa-gear" btnId="clearBtn"
            op="sys:clear:table" btnMethod="SystemTableInfoManager.clearDatabaseInfo()"/>
            <@permission btnValue="配置页面信息" btnClass="btn btn-info" iconClass="fa fa-gears" btnId="configPageBtn"
            op="sys:config:page" btnMethod="SystemTableInfoManager.configPageColumnInfo()"/>
            <@permission btnValue="自动生成代码" btnClass="btn btn-primary" iconClass="fa fa-gears" btnId="autoCodeBtn"
            op="sys:autocode:btn" btnMethod="SystemTableInfoManager.generateCode()"/>
            <@permission btnValue="一键生成所有代码" btnClass="btn btn-primary" iconClass="fa fa-gears" btnId="autoAllCodeBtn"
            op="sys:autoallcode:btn" btnMethod="SystemTableInfoManager.generateAllCode()"/>
            <div id="btnPermission" style="display:none">
              <div class="h-btn-group">
                <@permission btnType="edit" btnLink="true" btnValue="修改" btnClass="btn btn-info" btnId="editBtn"
                op="sys:tableinfo:edit"/>
                <@permission btnType="delete" btnLink="true" btnValue="删除" btnId="deleteBtn" btnClass="btn btn-danger"
                op="sys:tableinfo:del"/>
                <@permission btnType="view" btnLink="true" btnValue="查看" btnId="viewBtn" btnClass="btn btn-warning"
                op="sys:tableinfo:view"/>
              </div>
            </div>
          </div>
          <!--<div class="form-group">-->
          <!--<label class="col-sm-2 control-label">请选择生成代码方式：</label>-->
          <!--<div class="col-sm-2 col-xs-2 col-md-2" dict="generate_code_type" dicType='select' name="generateTypeGroup"-->
          <!--id="generateTypeGroup" value="" required="required" defaultValue='page'>-->
          <!--</div>-->
          <!--</div>-->
          <input id="generateType" name="generateType" type="hidden" value="page"/>
          <div class="panel-body">
            <table class="table table-striped table-bordered table-hover text-center" id="systemTableInfo_table"
                   style="width:100%"></table>
          </div>
        </div>
        <!-- 表格 end -->
      </div>
    </div>
    <!-- end: PAGE -->
  </div>
  <!-- end: MAIN CONTAINER -->

</div>
<#include "/common/jslib.html">

<script type="text/javascript">
    $(function () {
        SystemTableInfoManager = {
            init: function () {
                initDict(DICTURL, INDEX);
            },
            search: function () {
                var queryCond = {
                    tableCode: $("#tableCode").val(),
                    tableName: $("#tableName").val()
                };
                systemTableInfoTable.options.queryCond = queryCond;
                var tableId = systemTableInfoTable.options.tableId;
                $(tableId).DataTable().draw();
                $("[name=selectAll]:checkbox").prop("checked", false);
            },
            addSystemTableInfo: function () {
                var moduleId = "${moduleId!}";
                window.location.href = "/systemTableInfo/to-form?operation=add&moduleId=" + moduleId;
            },
            handleOperate: function (operate, id) {
                if (operate == "delete") {
                    SystemTableInfoManager.deleteSystemTableInfo(id);
                } else if (operate == "edit" || operate == "view") {
                    window.location.href = "/systemTableInfo/to-form?id=" + id + "&operation=" + operate;
                }
            },
            deleteSystemTableInfo: function (id) {
                var url = "/systemTableInfo/delete";
                var data = {
                    "id": id
                };
                Jmts.deleteItem("确定要删除吗？", url, data, function (result) {
                    if (result.success) {
                        Jmts.succTips("删除成功");
                        SystemTableInfoManager.search();
                    }
                });
            },
            //配置表字段信息
            configPageColumnInfo: function () {
                var chk_value = [];
                $('input[name="systemTableInfo_select"]:checked').each(function () {
                    chk_value.push($(this).val());
                });
                if (chk_value.length == 0) {
                    Jmts.warnTips("请选择一条记录");
                    return false;
                }
                if (chk_value.length > 1) {
                    Jmts.warnTips("只能选择一条记录");
                    return false;
                }
                var tableId = chk_value.join(",");
                var url = "/systemTableInfo/configPageColumnInfo?tableId=" + tableId;
                Jmts.openDialog("pageColumnInfo", url, "配置页面字段信息", 0, 0, 132);
            },
            //自动生成代码
            generateCode: function () {
                var chk_value = [];
                $('input[name="systemTableInfo_select"]:checked').each(function () {
                    chk_value.push($(this).val());
                });
                if (chk_value.length == 0) {
                    Jmts.alert("请选择要生成代码的表");
                    return false;
                }
                var generateType = $("#generateType").val();
                if (generateType == null || generateType == '' || generateType == 'undefined') {
                    Jmts.alert("请选择生成代码方式");
                    return false;
                }
                Jmts.confirm("生成代码之前请确保页面配置信息已经配置完整，确定要生成代码吗？", function () {
                    var url = "/systemTableInfo/generateCode?tableIds=" + chk_value.join(",") + "&moduleId=${moduleId}&generateType=" + generateType;
                    window.location.href = url;
                })
            },
            //自动生成所有代码
            generateAllCode: function () {
                var generateType = $("#generateType").val();
                if (generateType == null || generateType == '' || generateType == 'undefined') {
                    Jmts.alert("请选择生成代码方式");
                    return false;
                }
                Jmts.confirm("生成代码之前请确保页面配置信息已经配置完整，确定要生成模块下所有表的代码吗？", function () {
                    var url = "/systemTableInfo/generateAllCode?moduleId=${moduleId}&generateType=" + generateType;
                    window.location.href = url;
                })
            },
            syncDatabaseInfo: function () {
                var url = "/systemDatabaseTable/to-syncQuery?moduleId=${moduleId}&selectType=multiple";
                Jmts.openDialog("syncDatabaseInfo", url, "同步数据库信息", 500, 800, 132);
            },
            clearDatabaseInfo: function () {
                var url = "/systemTableInfo/clearDatabaseInfo";
                var data = {
                    "moduleId": '${moduleId!}'
                };
                Jmts.deleteItem("清空需要重新同步数据库信息，确定要清空吗？", url, data, function (result) {
                    if (result.success) {
                        Jmts.succTips("清空完成");
                      SystemTableInfoManager.search();
                    }
                });
            }
        }
        SystemTableInfoManager.init();
    });
</script>
<!-- js -->
<script type="text/javascript">
    (function () {
        // datatable插件
        systemTableInfoTable = new mi.datatable({
            tableId: '#systemTableInfo_table',
            headerList: [
                '<input type="checkbox" id="selectAll" name="selectAll"/>选择',
                '表名称',
                '表编码',
                '表对应实体类编码',
                '表的主键',
                '操作'
            ],
            headerName: [
                'chooseBox',
                'tableName',
                'tableCode',
                'tableEntityCode',
                'pkId',
                'operate'
            ],
            createdRow: function (row, data, dataIndex) {
                $(row).children('td').eq(1).attr('style',
                    'text-align:left;');
                $(row).children('td').eq(2).attr('style',
                    'text-align:left;');
                $(row).children('td').eq(3).attr('style',
                    'text-align:left;');
                $(row).children('td').eq(4).attr('style',
                    'text-align:left;');
                $(row).children('td').eq(0).attr('sort',
                    false);
            },
            ajaxUrl: '/systemTableInfo/listSystemTableInfo?moduleId=${moduleId!}',
            queryCond: function () {

            },
            columnDefs: [{
                orderable: false,//禁用排序
                targets: [0]   //指定的列
            }],
            dataSrc: function (data) {
                for (var i in data) {
                    var id = data[i]['id'];
                    if ($("#editBtn") != null && $("#editBtn") != undefined) {
                        $("#editBtn").attr("href", "javascript:SystemTableInfoManager.handleOperate('edit','" + id + "')");
                    }
                    if ($("#deleteBtn") != null && $("#deleteBtn") != undefined) {
                        $("#deleteBtn").attr("href", "javascript:SystemTableInfoManager.handleOperate('delete','" + id + "')");
                    }
                    if ($("#viewBtn") != null && $("#viewBtn") != undefined) {
                        $("#viewBtn").attr("href", "javascript:SystemTableInfoManager.handleOperate('view','" + id + "')");
                    }
                    var configDtr = mi.markLink({
                        href: '/systemColumnInfo/query?tableId=' + id + '&moduleId=${moduleId!}',
                        className: 'js-del-row-btn',
                        txt: '  表字段信息',
                        data: [
                            {id: id}
                        ]
                    });
                    var checkboxDtr = mi.markLink({
                        href: 'javascript:void(0)',
                        txt: selectType == "multiple" ?
                            "<input type='checkBox' id='systemTableInfo_select' name='systemTableInfo_select' value='" + id + "'/>" :
                            "<input type='radio' id='systemTableInfo_select' name='systemTableInfo_select' value='" + id + "'/>",
                        className: 'js-del-row-btn',
                        data: [
                            {id: id}
                        ]
                    });
                    data[i]['operate'] = $("#btnPermission").html() + configDtr;
                    data[i]['chooseBox'] = checkboxDtr;
                }
                return data;
            }
        });
    })();
</script>
<script type="text/javascript">
    $("#selectAll").click(function () {
        if ($(this).is(":checked")) {
            $("[name=systemTableInfo_select]:checkbox").prop("checked", true);
        } else {
            $("[name=systemTableInfo_select]:checkbox").prop("checked", false);
        }
    });
</script>
</body>
</html>
